//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#include <global.h>
#include "modeldatareferencecollectors.h"
#include <model/root.h>
#include <model/shooter.h>
#include <model/particletemplate.h>
#include <model/emittertemplate.h>
//
namespace ParticleTemplateReferenceCollector
{
using namespace model;
//
AtEmitterList collect_at_emitters(const model::ParticleTemplate &p_pt,const model::Root &p_root)
{
   AtEmitterList return_list;
   //
   for(QSet<EmitterTemplate*>::const_iterator eti=p_root.emitter_templates.begin();eti!=p_root.emitter_templates.end();++eti)
   {
      const EmitterTemplate *const et=*eti;
      for(int i=0;i<et->emitter_blocks.count();++i)
      {
         if(et->emitter_blocks.at(i).particle==&p_pt)
         {
            return_list.append(AtEmitter(et->get_id(),i));
         }
      }
   }
   //
   return return_list;
}
AtShooterList collect_at_shooters(const model::ParticleTemplate &p_pt,const model::Root &p_root)
{
   //TODO: implement if shooter ready
   return AtShooterList();
}
//
}
namespace EmitterTemplateReferenceCollector
{
using namespace model;
//
AtParticleList collect_at_particles(const model::EmitterTemplate &p_et,const model::Root &p_root)
{
   AtParticleList return_list;
   //
   for(QSet<ParticleTemplate*>::const_iterator pti=p_root.particle_templates.begin();pti!=p_root.particle_templates.end();++pti)
   {
      const ParticleTemplate *const pt=*pti;
      for(int i=0;i<pt->emitters.count();++i)
      {
         if(pt->emitters.at(i).emitter==&p_et)
         {
            return_list.append(AtParticle(pt->get_id(),i));
         }
      }
   }
   //
   return return_list;
}
AtEmitterList collect_at_emitters(const model::EmitterTemplate &p_et,const model::Root &p_root)
{
   AtEmitterList return_list;
   //
   for(QSet<EmitterTemplate*>::const_iterator eti=p_root.emitter_templates.begin();eti!=p_root.emitter_templates.end();++eti)
   {
      const EmitterTemplate *const et=*eti;
      for(int i=0;i<et->emitter_blocks.count();++i)
      {
         if(et->emitter_blocks.at(i).emitter==&p_et)
         {
            return_list.append(AtEmitter(et->get_id(),i));
         }
      }
   }
   //
   return return_list;
}
AtShooterList collect_at_shooters(const model::EmitterTemplate &p_et,const model::Root &p_root)
{
   //TODO: implement if shooter ready
   return AtShooterList();
}
//
}
